package com.soxing.braindata.web.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.soxing.braindata.dao.entity.Research;
import com.soxing.braindata.dao.entity.ResearchExt;
import com.soxing.braindata.dao.entity.Site;
import com.soxing.braindata.dao.service.ISiteService;
import com.soxing.braindata.domain.response.sync.SyncResponse;
import com.soxing.braindata.domain.rpc.OriginSite;
import com.soxing.braindata.domain.rpc.OriginSubject;
import com.soxing.braindata.service.manager.ISiteManager;
import com.soxing.braindata.service.sync.ISyncService;
import com.soxing.common.utils.response.WebResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/site")
@Api(value = "中心管理", tags = {"中心管理"})
public class SiteController {
    @Resource
    private ISiteManager siteManager;
    @Resource
    private ISiteService siteService;
    @Resource
    private ISyncService<OriginSite> syncSiteService;

    @PostMapping
    @ApiOperation(value = "新增课题")
    public WebResponse<Boolean> add(@RequestBody OriginSite originSite) {
        SyncResponse res = syncSiteService.syncData(originSite);
        if (res.getCode() == 0 ) {
            return WebResponse.success("添加成功");
        }else{
            return WebResponse.fail("添加失败");
        }
    }

    @PutMapping
    @ApiOperation(value = "更新中心")
    public WebResponse<Boolean> update(@RequestBody Site site) {
        if (site.getSitePkId() == null) {
            return WebResponse.fail("中心编码为空");
        }
        return siteManager.update(site);
    }

    @PostMapping("/delete/{id}")
    @ApiOperation(value = "基于id删除")
    public WebResponse<Boolean> deleteById(@PathVariable("id") Integer id) {
        return siteManager.deleteById(id);
    }
}
